<?php
header( 'Content-Type:application/json; charset=utf-8' );
session_start();
if ( empty( $_SESSION[ 'userinfo' ] ) ) {
    $result = [
        'code' => '403',
        'msg' => '未登录，请登录',
    ];
    echo json_encode( $result );
    exit ;
}
$input = file_get_contents( 'php://input' );
$arr = json_decode( $input, true );
$id = $arr[ 'id' ] ?? '';

$sql = "SELECT * FROM zyh_course WHERE cou_id IN (SELECT cou_id FROM zyh_tch_cou WHERE tch_id = '".$id ."');";

$dbms = 'mysql';
$host = '127.0.0.1';
$dbName = 'g09short';
$user = 'root';
$pass = 'G09short.';
$dsn = "$dbms:host=$host;dbname=$dbName";

try {
    $dbh = new PDO( $dsn, $user, $pass );
    $stmt = $dbh->query( $sql, PDO::FETCH_ASSOC );
    $stmt->setFetchMode( PDO::FETCH_ASSOC );
    $row = $stmt->fetchAll();
    $result = [
        'code' => '200',
        'msg' => '查询成功！',
        'data' => $row
    ];

    $dbh = null;

    echo json_encode( $result );
} catch ( PDOException $e ) {
    $result = [
        'code' => '500',
        'msg' => '$e->getMessage()',
    ];
    die($result);
}
?>